//
//  MainDefaulSearchVC_V4.m
//  ZITHER
//
//  Created by weixin on 2018/11/19.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MainDefaulSearchVC_V4.h"

#import "MainSearchBottom.h"


#import "MainDefaulSearctVC.h"


@interface MainDefaulSearchVC_V4 ()

@property (nonatomic,strong)MainSearchBottom *bottomView;

@property (nonatomic,strong)BaseBtn *moreBtn;//展示更少或更多



@end

@implementation MainDefaulSearchVC_V4

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setNav];
    
    [self setUI];
    
}

-(void)setNav{
    [self.baseNavigationView setHiddenNav:NO VC:self];
    /* TODO: ================= 导航栏V4样式 =================*/
    [self.baseNavigationView NavigationBarStyle:1];
    self.baseNavigationView.navViewStyle.title.text = @"条件寻表";
    self.baseNavigationView.navViewStyle.leftBtn.hidden = YES;
    self.baseNavigationView.leftButton1.hidden = YES;
    //    self.baseNavigationView.navViewStyle.isShowShadow = NO;
    //    self.baseNavigationView.bottomLineView.hidden = YES;
}

-(void)setUI{
    
    [self.view addSubview:self.moreBtn];
    
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.baseNavigationView.navViewStyle.title.mas_centerY).offset(0);
        make.right.equalTo(self.view).offset(-20);
        make.height.width.mas_equalTo(30);
    }];
    
    [self.view addSubview:self.tbv];
    
    [self.view addSubview:self.bottomView];
    
}

-(MainDefaulSearchVC_V4_Tbv *)tbv{
    if (!_tbv) {
        _tbv = [[MainDefaulSearchVC_V4_Tbv alloc]initializeFrame:CGRectMake(0,NaviHeight , kScreenW, kScreenH-NaviHeight-50) isMj:0 isEstimatedRowHeight:YES addRegisterNib:@[@"MainDefaulSearchTypeOne_V4_Cell",@"MainDefaulSearchTypeTwo_V4_Cell"]];
    }
    return _tbv;
}

-(MainSearchBottom *)bottomView{
    if (!_bottomView) {
        _bottomView = [[MainSearchBottom alloc]initWithFrame:CGRectMake(0, kScreenH-50, kScreenW, 50)];
        _bottomView.backgroundColor = [UIColor colorWithHex:@"969696"];
        
        @weakify(self);
        [[_bottomView.btnCancel rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [self.navigationController popViewControllerAnimated:YES];
        }];
        
        [[_bottomView.btnDone rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            
            [self pushMainDefaulSearctVC];
//            MainDefaulSearchVC *vc = [[MainDefaulSearchVC alloc] init];
//
//
//            letterModel *mdoel2 = self.tbv.arrM[1];
//            vc.viewTop.brandId = mdoel2.id;
////            vc.arrSelect = self.arrM;
//
//            NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:self.tbv.arrM];
//            if ([arr[0] isEqualToString:@"价格范围"]) {
//                arr[0] = @"不限";
//            }
//
//            letterModel *model = arr[1];
//            if ([model.brandName isEqualToString:@"品牌"]) {
//                arr[1] = @"品牌";
//            }else{
//                arr[1] = model.brandName;
//            }
//
////            if (<#condition#>) {
////                 arr[0]
////            }
//
//
//            for (int i = 2; i < arr.count; i++) {
//                optionssModel *modelA = [[optionssModel alloc]init];
//                NSDictionary *dic = self.tbv.arrM[i];
//                NSString *str = dic[@"num"];
//
//                if (str.length == 0) {
//                    modelA.name = @"不限";
//                    arr[i] = @[modelA];
//                }else{
//                    modelA.name = str;
//                    arr[i] = @[modelA];
//                }
//            }
//
//            vc.arrSelect = arr;
//            vc.modelSelect = self.tbv.model;
//
//
//            //条件搜索
//            vc.search.btn3.hidden = NO;
//            [self.navigationController pushViewController:vc animated:YES];
        }];
        
    }
    return _bottomView;
}

-(void)pushMainDefaulSearctVC{
    
    if (self.indexType == 1) {
        if (self.block) {
            self.block(self.tbv.arrM);
        }
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{
        /** 条件寻表 */
        MainDefaulSearctVC * vc = [[MainDefaulSearctVC alloc]init];
        vc.indexType = 1;
        vc.arrM = self.tbv.arrM;
        vc.model = self.tbv.model;
        
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    
}

-(BaseBtn *)moreBtn{
    if (!_moreBtn) {
        _moreBtn = [[BaseBtn alloc]initializeFrame:CGRectMake(0, 0, 0, 1) NormalText:@"更少" NormalTextColor:[UIColor blackColor] SeleText:@"更多" SeleTextColor:[UIColor blackColor] font:10 isBold:NO];
        _moreBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
        
        /** 按钮点击案例 */
        @weakify(self);
        [[_moreBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            
            self.moreBtn.selected = !self.moreBtn.selected;
            
            if (self.moreBtn.selected) {
                self.tbv.indexType = 1;
            }else{
                self.tbv.indexType = 0;
            }
            [self.tbv reloadData];
        }];

        _moreBtn.hidden = YES;

    }
    return _moreBtn;
}

-(void)setIndexType:(NSInteger)indexType{
    _indexType = indexType;
    if (indexType == 1) {
        self.moreBtn.hidden = NO;
    }

}

@end
